-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(grpc): support Ed25519 message signing and verification #1667
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1667 +/- ##
==========================================
+ Coverage 75.07% 76.37% +1.30%
==========================================
Files 234 241 +7
Lines 12156 18469 +6313
==========================================
+ Hits 9126 14106 +4980
- Misses 2582 3901 +1319
- Partials 448 462 +14 |
Thank you so much for this amazing PR. It’s great to see how smart you are in understanding the logic and fixing this issue. Good job! First of all, it’s great to see that you can detect the type of maybeBLSPublicKey := func(str string) bool {
return strings.Contains(strings.ToLower(str), "public1p")
}
maybeEd25519PublicKey := func(str string) bool {
return strings.Contains(strings.ToLower(str), "public1r")
}
switch {
case maybeBLSPublicKey(req.PublicKey):
/// ...
case maybeEd25519PublicKey(req.PublicKey):
/// ...
default:
return nil, status.Error(codes.InvalidArgument, "invalid public key")
} Now, we can make another improvement here. We can define a function like this: func (*utilServer) publicKeyFromString(pubStr string) (crypto.PublicKey, error) {
maybeBLSPublicKey := func(str string) bool {
return strings.Contains(strings.ToLower(str), "secret1p")
}
maybeEd25519PublicKey := func(str string) bool {
return strings.Contains(strings.ToLower(str), "secret1e")
}
switch {
case maybeBLSPublicKey(pubStr):
blsPub, err := bls.PublicKeyFromString(pubStr)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid private key")
}
return blsPub, nil
case maybeEd25519PublicKey(pubStr):
ed25519Pub, err := ed25519.PublicKeyFromString(pubStr)
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid private key")
}
return ed25519Pub, nil
default:
return nil, status.Error(codes.InvalidArgument, "invalid private key")
}
} Finally we can make the same for |
@b00f Sure. Thanks for the review. I was not aware that the public key also has the same structure. Tried to find across the code but couldn't. Thanks for the suggestion on the interface as well. I just saw two different structs and missed the interface. I will implement those. |
@b00f Made the changes. Can you please check. |
You can use |
I decided to use error checking instead of prefix checking. Using error checking makes this much simpler, reducing the code by almost 20 lines.
@BuidlWithShivam |
Good job @BuidlWithShivam |
@BuidlWithShivam Do you like to join Pactus DEV team? |
@b00f I am looking for opportunities in Blockchain. Sure we can have a chat about it. |
@BuidlWithShivam Please join our Discord and let's have chat there: https://discord.gg/pactus |
@b00f Joined. |
Fix for the issue : Sign and verify message by ed25519